package top.zhangjianyong.blog.params.user;

import cn.hutool.core.util.StrUtil;
import jakarta.validation.constraints.NotBlank;
import java.time.LocalDate;
import org.mindrot.jbcrypt.BCrypt;

/**
 * 用户新增修改入参
 *
 * @author zhangjianyong
 * @since 2024/7/21 下午4:55
 */
public record UserSaveOrUpdateParam(
    Long id,
    @NotBlank(message = "用户名不能为空") String username,
    String password,
    String avatar,
    String nickname,
    String realName,
    LocalDate birthday,
    String email,
    String phone,
    String gitee,
    String github,
    String description,
    String personalSummary,
    String blogSummary) {
  public UserSaveOrUpdateParam {
    // 密码加密
    if (StrUtil.isNotBlank(password)) {
      password = BCrypt.hashpw(password, BCrypt.gensalt());
    }
  }
}
